package com.suxin.netty.coder;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

/**
 * @author Tang
 * @classname MyDecoderInt
 * @description [ TODO ]
 * @date 2021/1/8 21:48
 */
public class MyInDecoderInt extends ByteToMessageDecoder {

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        // 解码器
        System.out.println("[" + ctx.channel().localAddress() + "] MyInDecoderInt 解码器执行..." );
        if (in.readableBytes() >= 4) {
            out.add(in.readInt());
        }
    }
}